<?php
include_once('db.php');
$username_admin = $_POST["username_admin"];
$password_admin = $_POST["password_admin"];
$password_admin = md5($password_admin);
$sql = "select * from users where username='{$username_admin}' and password='{$password_admin}';";
$result = mysqli_query($link,$sql);
$rows = mysqli_fetch_all($result,MYSQLI_ASSOC);
if($rows!=[]&&$rows!=null&&$rows!=""&&$rows!=0){
	$newRow['status'] = 1; // 状态码
	if($_POST["check"]=="true"){
		$times = time() + 60 * 60 * 24 * 3;
		setcookie("loginStatus",$username_admin,$times,"/");
		setcookie("loginpassword",$password_admin,$times,"/");
	}else{
		session_start();
		$_SESSION['loginStatus'] = $username_admin;
		$_SESSION['loginpassword'] = $password_admin;
	}
	$newRow['status'] = $username_admin;
	$newRow['msg'] =  "登录成功";
}else{
	$newRow['status'] = 0;
	$newRow['msg'] = "登录失败，账号或密码错误";
}
echo json_encode($newRow);
?>